var prefix = api + "/admin/param";
var oper = getQueryString('oper')
var id = getQueryString('id')

$(function() {
	renderDictFilter('#status', 'status_type')
	renderDictFilter('#systemFlag', 'dict_type')
	renderDictFilter('#publicType', 'param_type')
	$('#oper').val(oper)
	if (oper === 'edit' || oper === 'view') {
		paramDetail(id)
	}

	jQuery.validator.addMethod("format",function(value,element){
		var account = /^[A-Z_]+$/;
		return account.test(value);
	  },"请输入大写英文、下划线");

	jQuery.validator.addMethod("format1", function (value, element) {
		var account = /^[a-zA-Z0-9_]*$/;
		return account.test(value);
	}, "只支持字母、数字、下划线");
});

function paramDetail(id){
	$.operate.get(api + '/admin/param/' + id, function (res) {
		res.data.oper = oper
		applyDrawing('#editForm',res.data)
	}, false)
}

$("#editForm").validate({
	onkeyup : false,
	rules : {
		publicName : {
			required: true
		},
		publicKey : {
			required: true,
			format: true
		},
		publicValue : {
			required: true
		},
		validateCode : {
			required: true,
			format1: true
		},
		systemFlag : {
			required: true
		},
		publicType : {
			required: true
		},
	},
	messages: {
		publicName: {
		  required: "请输入名称"
		},
		publicKey: {
		  required: "请输入键"
		},
		publicValue: {
		  required: "请输入值"
		},
		validateCode: {
		  required: "请输入编码"
		},
		systemFlag: {
		  required: "请选择类型"
		},
		publicType: {
		  required: "请选择类型"
		}
	  },
	focusCleanup : true
});
	    
function submitHandler() {
	if ($.validate.form()) {
		$.common.ajaxCommitForm($('#editForm'),false);
    	return false;
	}
}